【压测】wrk拓展

wrk自定义变量值

wrk = {
  scheme  = "http",
  host    = "localhost",
  port    = nil,
  method  = "GET",
  path    = "/",
  headers = {},
  body    = nil,
  thread  = <userdata>,
}

基本配置:

wrk.method = "POST"
wrk.headers["Content-Type"] = "application/json"
wrk.body='{}'

基本使用

-- 生成request的string
wrk.format(method, path, headers, body)
-- 获取域名的IP和端口
wrk.lookup(host, service)
-- 判断是否能连接
wrk.connect(addr)

高级使用

-- 请求测试打印response的内容
function response(status, headers, body):
    print(body)
end

-- 请求构建随机id
init = function(args)
    body_table = {}
    model = {"lr", "rf"}
    pkgs = {11, 31, 53}
    n=1
    for i = 0, 2 do
        for j = 1, 2 do
            for k = 1, 3 do
                body_table[n]="{\"result_hdfs\":\"/dw_ext/ad/ads_dm/lookalike/competition/sample_data/train_data_liuyan22_"..pkgs[k].."_"..i.."_"..model[j].."_predict\",\"delimiter\":\"\\t\",\"team\":1}"
                n = n + 1
            end
        end
    end
    math.randomseed(tostring(os.time()):reverse():sub(1, 7))
end

reques = function()
    local n = math.random(18)
    return wrk.format(nil, nil, nil, boday_table[n])
end

lua中有8中基本的数据类型nil、boolean、number、string、userdata、function、thread 和 table

nil代表空值或者无效值或者False

results matching ""

    No results matching ""